package demo6;

class Animal {
    public String name;
    public int age;

    public void eat() {
        System.out.println(this.name + " 正在吃饭");
    }
}

class Dog extends Animal {
    public int age = 12;
    public int test = 20;

    public void bark() {
        System.out.println(this.name + "旺旺叫~");
    }

    @Override
    public void eat() {
        System.out.println(this.name + " 正在吃狗粮！" + "重写的eat方法");
    }
}

public class Test {
    public static void main(String[] args) {
        Animal animal = new Animal();
        animal.eat();
        System.out.println(animal.age);
        //animal.bark();//编译报错
        //System.out.println(animal.test);//编译报错

        System.out.println("=================================");

        Animal animal2 = new Dog();
        animal2.eat();
        System.out.println(animal2.age);
        //animal2.bark();//编译报错
        //System.out.println(animal2.test);//编译报错
    }
}
